package com.exer;

/**
 * 模拟一个trim()，去除字符串两端的空格
 */
public class StringDemo {

    public static void main(String[] args) {
        String str = "    dsanl djaslndl dnsal     ";
        str = "dsdjaslndl dn";
        System.out.println(simulationTrim(str));
    }

    public static String simulationTrim(String str){
        if(str != null){
            String str2 = str.replaceAll("^\\s+", "").replaceAll("\\s+$", "");
            return str2;
        }
        return str;
    }
}
